www.gusucode.com > Student Competition - Code Generation Training工具箱matlab源码 > Student Competition - Code Generation Training/CodeGenFX/Files/ch4_customCgWithSL/matFileExample.m

    %% Find EXE file and delete for forcing regeneration

% Copyright 2018 The MathWorks, Inc.

clc
close all
exeStr = which('controller.exe');
if(~isempty(exeStr))
    delete(exeStr)
end

%% Look for generated code folder, if not generate code
csolncgfolder = exist('controller_ert_rtw', 'dir');

if(csolncgfolder ~= 7)
    load_system('controller');
    rtwbuild('controller');
end

%% Replace example main with custom main
currFolder = cd('controller_ert_rtw');
copyfile([currFolder '\my_main\ert_main.c']) 

%% Delete OBJ files to force regeneration
delete('*.obj');

%% Run batch file to compile and build new executable
!controller.bat

%% Run executable
cd(currFolder)
!controller.exe

%% Load MAT file and plot results
load('controller.mat')
plot(rt_tout, rt_yout)